/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-11-24
 * Time: 23:02
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;

using tools;

using Labb4.Pooman.Players;

namespace Labb4.Pooman.Game
{
	/// <summary>
	/// Base class for the different states of the game.
	/// 
	/// Implements the State design pattern
	/// </summary>
	public abstract class GameState //state
	{
		#region members
		
		/// <summary>
		/// Reference to the PoomanMain object
		/// </summary>
		protected PoomanMain		m_PoomanMain;
		/// <summary>
		/// One stick played by the players
		/// </summary>
		protected Stick				m_Stick;
		/// <summary>
		/// A swarm of players, iterated through as the game progresses through a stick
		/// </summary>
		protected PlayerSwarm		m_Swarm;
		
		/// <summary>
		/// The time cards are displayed laying still on the table before being removed after a stick ends
		/// </summary>
		protected int				m_CounterForDisplayingWonCards;
		/// <summary>
		/// If a winner of a stick is found, this is true, otherwise false
		/// </summary>
		protected bool				m_FoundWinnerOfLastStick;
		
		/// <summary>
		/// For optimization
		/// </summary>
		protected PlayerManager		m_PlayerManager;
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, initializes members
		/// </summary>
		/// <param name="poo">The current PoomanMain reference</param>
		public GameState(PoomanMain poo)
		{
			m_PoomanMain = poo;
			m_Stick = new Stick();
			m_Swarm = new PlayerSwarm();
			
			m_PlayerManager = PlayerManager.Instance;
		}
		
		#endregion
		
		#region methods
		
		/// <summary>
		/// Saves the stick and the swarm to a List of string
		/// </summary>
		/// <param name="fileContent">The List of string to save the stick and the swarm to</param>
		public void Save(List<string> fileContent)
		{
			m_Stick.Save(fileContent);
			m_Swarm.Save(fileContent);
		}
		
		/// <summary>
		/// Loads the stick and the swarm from the given file
		/// </summary>
		/// <param name="config">The file to load from</param>
		public void Load(Config config)
		{
			m_Stick.Load(config);
			m_Swarm.Load(config);
		}
		
		#endregion
		
		#region virtuals
		
		/// <summary>
		/// Resets the members to initial values
		/// </summary>
		/// <param name="firstPlayerInSwarm"></param>
		public virtual void ResetPhase(Player firstPlayerInSwarm)
		{
			m_Swarm.Clear();
			m_Stick.Clear();
			
			m_CounterForDisplayingWonCards = 0;
			m_FoundWinnerOfLastStick = false;
		}
		
		#endregion
		
		#region abstracts
		
		/// <summary>
		/// The last actions of the phase, different implementations depending on what phase is ending
		/// </summary>
		public abstract void LastActionOfThePhase();
		/// <summary>
		/// Plays the next stick, different implementations depending on what phase the game is in
		/// </summary>
		/// <param name="deltaTime"></param>
		public abstract void PlayNextStick(int deltaTime);
		
		#endregion
	}
}
